package com.zhuojy.equity.mall.admin.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhuojy.equity.mall.admin.common.entity.TFlow;
import com.zhuojy.equity.mall.admin.common.entity.vo.TFlowExportEntity;
import com.zhuojy.equity.mall.admin.common.pojo.JsonResult;
import com.zhuojy.equity.mall.admin.common.utils.ExcelUtils;
import com.zhuojy.equity.mall.admin.dal.mapper.TFlowMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class TFlowService extends ServiceImpl<TFlowMapper, TFlow> {
    /**
     * 资金流水条查分页
     * @param tFlow
     * @param pageNum
     * @param pageSize
     * @return
     */
    public JsonResult findflowPagination(TFlow tFlow, Integer pageNum, Integer pageSize) {
        Page<TFlow> page = new Page<>(pageNum,pageSize);
        IPage<TFlow> tFlowIPage = this.baseMapper.findflowPagination(tFlow,page);
        return JsonResult.success(tFlowIPage.getRecords(),tFlowIPage.getTotal());
    }

    /**
     * 资金流水导出
     * @param response
     */
    public void exportExcel(HttpServletResponse response) {
        //多表导出
        List<TFlowExportEntity> list = this.baseMapper.getTFlowExportEntity();
        ExcelUtils.export(response, "导出数据列表", list, TFlowExportEntity.class);
    }

    /**
     * 资金流水下拉列表框
     * @return
     */
    public List<TFlow> findoptions() {
      return this.baseMapper.findoptions();
    }
}
